﻿/// <reference path="jquery-1.11.2.min.js" />
/// <reference path="MicrosoftAjax.js" />

Type.registerNamespace("DeluxeSources.Scripts");

DeluxeSources.Scripts.FileSelection = function () {
    /// <summary>
    /// 文件选择类。
    /// </summary>

    this.RealSelectionContainer = $("#HtmlDiv_FileSelectorContainer");
    this.SimulateSelectionContainer = $("#HtmlDiv_SimulateFileSelectorContainer");
    this.UploadControl = $("#HtmlInput_FileSelector");
}

DeluxeSources.Scripts.FileSelection.prototype = {
    Initialize: function () {
        /// <summary>
        /// 页面初始化。
        /// </summary>
        var me = this;
        this.RealSelectionContainer.fadeTo("fast", 0).css("z-index", 2).css("position", "absolute");
        this.SimulateSelectionContainer.css("position", "absolute").css("left", String.format("{0}px", this.RealSelectionContainer.offset().left)).css("top", String.format("{0}px", this.RealSelectionContainer.offset().top)).css("z-index", 1);

        this.UploadControl.change(function () {
            var regex = /\.xlsx?$/gi;
            if (regex.test($(this).val())) {
                $("form").submit();
            }
            else alert("请选择一个扩展名为.xls或.xlsx的文件");
        });
    }
}

Type.registerClass("DeluxeSources.Scripts.FileSelection");

$(document).ready(function () {
    var me = new DeluxeSources.Scripts.FileSelection();

    me.Initialize();
});